package b2.widget
{
	import flash.display.Sprite;
	import flash.text.*;

	public class BubbleMessage extends Sprite
	{
		public function BubbleMessage(text:String, leftFlag:Boolean = false, roundRecColor:uint = 0xFFFF00, txtColor:uint = 0x000000)
		{
			super();
			var roundRecContainer:Sprite = new Sprite();
			//加载文字
			var titleText:TextField = new TextField();
			titleText.selectable = false;
        	titleText.autoSize = TextFieldAutoSize.LEFT;
			titleText.defaultTextFormat = new TextFormat("微软雅黑", 15, txtColor);
			titleText.text = text;
			titleText.width = 120;
			titleText.wordWrap = true;
			roundRecContainer.addChild(titleText);
			//加载背景
			var rrect:Sprite = new Sprite();
			rrect.graphics.lineStyle(2, roundRecColor);
			rrect.graphics.beginFill(0xFFFFFF);
			//圆角矩阵
			rrect.graphics.moveTo(-5, 5);
			rrect.graphics.curveTo(-5, -5, 5, -5);
			rrect.graphics.lineTo(roundRecContainer.width - 5, -5);
			rrect.graphics.curveTo(roundRecContainer.width + 5, -5, roundRecContainer.width + 5, 5);
			rrect.graphics.lineTo(roundRecContainer.width + 5, roundRecContainer.height - 5);
			rrect.graphics.curveTo(roundRecContainer.width + 5, roundRecContainer.height + 5, roundRecContainer.width - 5, roundRecContainer.height + 5);
			if (leftFlag)
			{
				rrect.graphics.lineTo(20, roundRecContainer.height + 5);
				rrect.graphics.lineTo(-10, roundRecContainer.height + 25);
				rrect.graphics.lineTo(5, roundRecContainer.height + 5);
			}
			else
			{
				rrect.graphics.lineTo(roundRecContainer.width - 5, roundRecContainer.height + 5);
				rrect.graphics.lineTo(roundRecContainer.width + 10, roundRecContainer.height + 25);
				rrect.graphics.lineTo(roundRecContainer.width - 20, roundRecContainer.height + 5);
			}
			rrect.graphics.lineTo(5, roundRecContainer.height + 5);
			rrect.graphics.curveTo(-5, roundRecContainer.height + 5, -5, roundRecContainer.height - 5);
			addChild(rrect);
			rrect.alpha = 0.9;
			addChild(roundRecContainer);
		}
		
	}
}